package test;


import java.awt.Image;
import java.awt.Toolkit;
import java.awt.image.PixelGrabber;

public class Imagen {
    
    public Imagen() {
    }
    
    public static void processImage(String inFile, String outFile) {
        
        Image image = Toolkit.getDefaultToolkit().getImage(inFile);
        
        try {
            
            PixelGrabber grabber =new PixelGrabber(image, 0, 0, -1, -1, false);
            
            if (grabber.grabPixels()) {
                int width = grabber.getWidth();
                int height = grabber.getHeight();
                
                if (isGreyscaleImage(grabber)) {
                    byte[] data = (byte[]) grabber.getPixels();
                    
                    // Process greyscale image ...
                    
                }
                else {
                    int[] data = (int[]) grabber.getPixels();
                    
                    // Process Color image
                    
                }
            }
        }
        catch (InterruptedException e1) {
            e1.printStackTrace();
        }
    }
    
    public static final boolean isGreyscaleImage(PixelGrabber pg) {
        return pg.getPixels() instanceof byte[];
    }
    
    public static void main(String args[]) {
        /*
        if (args.length > 1) {
            processImage(args[0], args[1]);
            System.exit(0);
        } else {
            System.err.println(
                    "usage: java PixelGrabberTest <infile> <outfile>");
            
            System.exit(2);
        }
          */
    	processImage("E:\\2.jpg","E:\\3.jpg");
    }
}